const DoublyLinkedList = require("../template.js")

/** 1. 转换方法测试 */
function testTransfer() {
  const arr = [10, 20, 30]
  const link = DoublyLinkedList.fromArray(arr)

  // 测试转链表
  console.log(
    "1.0 数组转链表:",
    link.size === 3 && link.head.value === 10 && link.tail.value === 30 && link.head.next?.value === 20
  )
  // 测试转数组
  const converted = DoublyLinkedList.toArray(link)

  console.log(
    "1.1 链表转数组:",
    converted.length === 3 && converted[0] === 10 && converted[2] === 30
  )

  // 测试空数组转换
  const emptyList = DoublyLinkedList.fromArray([])
  console.log("1.2 空数组转换:", emptyList.size === 0)

  // 测试转字符串
  const str = DoublyLinkedList.toString(link)
  console.log(
    "1.3 链表转字符串:",
    typeof str === "string" && str === "10,20,30"
  )

  console.log("--------------------")
}

testTransfer()

module.exports = testTransfer
